package demo02;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-04-08
 * Time: 20:15
 */
//姓名比较器
class NameCompare implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        //根据姓名进行排序
        return (o1.name).compareTo( o2.name) ;
    }
}

public class Main {
    public static void main(String[] args) {
        Student s1 = new Student("a",20);
        Student s2 = new Student("b",10);
        Student s3 = new Student("c",30);
        Student[]students = {s1, s2, s3};
        NameCompare nameCompare = new NameCompare();
        Arrays.sort(students, nameCompare);
        System.out.println( Arrays.toString(students));
    }
}
